<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
        
        <title>Safe URI Decoding Documentation</title>
        
        <script src="/js/greyspots.js" type="text/javascript"></script>
        <link href="/css/greyspots.css" type="text/css" rel="stylesheet" />
        
        <script src="/js/ace/ace.js" data-ace-base="/js/ace/" type="text/javascript" charset="utf-8"></script>
        <script src="/js/ace/ext-language_tools.js" type="text/javascript"></script>
        <script src="/js/ace/ext-searchbox.js" type="text/javascript"></script>
        
        <script src="doc-library/doc.js" type="text/javascript"></script>
        <link href="doc-library/doc.css" type="text/css" rel="stylesheet" />
    </head>
    <body>
        <gs-jumbo>
            <h1 class="text-center">Safe URI Decoding</h1>
        </gs-jumbo>
            
        <gs-container min-width="sml;med;lrg">
            <h3>Function:</h3>
            <pre><code>GS.safeDecodeURIComponent(&lt;STRING-TO-DECODE&gt;);</code></pre>
            
            <h3>Description:</h3>
            <p>The GS.safeDecodeURIComponent runs the Javascript decodeURIComponent function but when it runs into a decoding error it just returns the string it was sent without any modifications. So if the string "asdf%26asdf" was sent than it would return "asdf&asdf" but if the string "asdf%z2asdf" was sent it would return the same string because "%z2" is not a valid URI code. See also: <a href="doc-jslib-url-state.html">URL State Functions</a> and <a href="doc-jslib-query-string.html">Query String</a>.</p>
            
            <h1>Examples:</h1>
            <div class="doc-example-description">
                <span class="h3">Skeleton Example:</span><br />
                <p>When you click the "Safe" button the text of the first text control will be run through the GS.safeDecodeURIComponent function and put in the second text control. When you click the "Not Safe" button the text of the first text control will be run through the decodeURIComponent function and put in the second text control. If there is an error when decodeURIComponent is run than the error text will be put into the second text control.</p>
            </div>
            <gs-doc-example>
                <template for="html" height="18">
                    <gs-text id="text-to-convert" value="%z2"></gs-text>
                    <gs-grid>
                        <gs-block><gs-button onclick="testSafe()" remove-right>Safe</gs-button></gs-block>
                        <gs-block><gs-button onclick="testUnsafe()" remove-left>Not Safe</gs-button></gs-block>
                    </gs-grid>
                    <gs-text id="text-converted"></gs-text>
                </template>
                <template for="js" height="18">
                    function testSafe() {
                        document.getElementById('text-converted').value = GS.safeDecodeURIComponent(document.getElementById('text-to-convert').value);
                    }
                    
                    function testUnsafe() {
                        try {
                            document.getElementById('text-converted').value = decodeURIComponent(document.getElementById('text-to-convert').value);
                        } catch (e) {
                            document.getElementById('text-converted').value = e;
                        }
                    }
                </template>
            </gs-doc-example>
        </gs-container>
    </body>
</html>